<?php
session_start();
//包含头
include '../PHP/head.php';
?>
<?php
//包含bootstrap的顶端按钮
include '../PHP/menu.php';
?>

<br />
<br />
<p class="text-center lead">澄清校核</p>
<?php
//校核澄清
//1. 退回，将由专业工程师修改后重新提交校核，澄清状态修改为“修改”；
//2. 通过，澄清状态修改为“校核”，项目表中专业状态修改为“2” - 澄清中。
//接收操作
if (isset($_GET['clarification_id'])) {
	$clarification_id = $_GET['clarification_id'];
	$checked = $_GET['checked'];
	require_once ('../FNS/db_fns.php');
		
	if($checked == 'ok') {
		$db = db_connect();
		//设置澄清状态为“校核”
		$query="update clarification set status = '校核' where id = '".$clarification_id."'";
		$result=$db->query ($query);
		if ($result){
			echo "<br />";
			echo "<p>校核通过。</p>";
		}else{
			echo "<br />";
			echo"<p>校核失败！</p>";
	
		
		}
		//修改专业状态为"2" - 澄清中。
		$query="select project_id, subject from clarification where id = '".$clarification_id."'";
		$result=$db->query ($query);
		$row=$result->fetch_assoc ();
		$project_id = $row['project_id'];
		$subject = stripslashes ($row['subject']);
		
		$result->free();
		
		$query="update projects set ".$subject."_flag = '2' where id = '".$project_id."'";
		$result=$db->query ($query);
		$db->close();
	}
	if($checked == 'back') {
		$db = db_connect();
		
		$query="update clarification set status = '修改' where id = '".$clarification_id."'";
		$result=$db->query ($query);
		if ($result){
			echo "<br />";
			echo "<p>已退回。</p>";
		}else{
			echo "<br />";
			echo"<p>退回失败！</p>";
	
		
		}
		$db->close();
	}
}


//从clarification中搜出状态是“进行中”、“subjecti”是自己专业的澄清
require_once ('../FNS/db_fns.php');
//弄到专业号
$subject = substr ($user_position, 1, 2);
$subject = strtolower ($subject);


$db = db_connect();
$query="select clarification.id, clarification.ref, clarification.des, projects.code as project_code, projects.name as project_name, users.name as issue_name from clarification 
	inner join projects on clarification.project_id = projects.id 
	inner join users on clarification.user_id = users.id 
	where clarification.status = '提交' and clarification.subject = '".$subject."' order by clarification.id";
$result=$db->query ($query);
if (!$result) {
	echo "<br />";
	echo "<p>没有未校核的澄清。</p>";
	echo "<p>subject是".$subject."</p>";
	echo "</div>";
	echo "</body>";
	$db->close();
exit;
}
$num_result=$result->num_rows;
//写表头
echo "<table class='table table-striped'>";
echo "<tr>";
	echo "<td align='center' class='info'><strong>报价编号</strong></td>";
	echo "<td align='center' class='info'><strong>项目名称</strong></td>";
	echo "<td align='center' class='info'><strong>客户文件参考</strong></td>";
	echo "<td align='center' class='info'><strong>澄清内容</strong></td>";
	echo "<td align='center' class='info'><strong>提出人</strong></td>";
	echo "<td align='center' class='info'><strong>操作</strong></td>";
echo "</tr>";



//循环编制表格
for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$project_code = stripslashes ($row['project_code']);
	$project_name = stripslashes ($row['project_name']);
	$ref = stripslashes ($row['ref']);
	$des = stripslashes ($row['des']);
	$issue_name = stripslashes ($row['issue_name']);
	$clarification_id = stripslashes ($row['id']);
	
	$link_ok = "../PHP/show_clarification_issue.php?clarification_id=".$clarification_id."&checked=ok";
	$link_back = "../PHP/show_clarification_issue.php?clarification_id=".$clarification_id."&checked=back";
	
	echo "<tr>";
	echo "<td align ='center'>".$project_code."</td>";
	echo "<td align ='center'>".$project_name."</td>";
	echo "<td align ='center'>".$ref."</td>";
	echo "<td align ='center'>".$des."</td>";
	echo "<td align ='center'>".$issue_name."</td>";
	echo "<td align='center'>
		<a class='btn btn-success btn-sm' href='".$link_ok."' role='button'>通过</a>
		<a class='btn btn-danger btn-sm' href='".$link_back."' role='button'>退回</a>
		</td>";
	echo "</tr>";
	
}
echo "</table>";


$result->free();
$db->close();
?>




</div>
</body>
</html>